import Taro from "@tarojs/taro";
import {submit, update} from "@/chaos/functions/Data";
import {get, login, location, navigateTo,} from "@/chaos/functions/Taro";


export async function doLogin({referrer = "", source = ""}, force = false) {
  if (!force && get("token")) {
    return;
  }
  const {mu, token} = await submit("wxmini/login", {
    code: await login(),
    referrer,
    source,
    loginPlatform: 'sybsidy'
  });
  Taro.setStorageSync("mu", mu);
  Taro.setStorageSync("token", token);
  await doLocation();
}


async function doLocation() {
  const {longitude: lng, latitude: lat} = await location();
  Taro.setStorageSync("lng", lng);
  Taro.setStorageSync("lat", lat);

  await update("iya_user", "", {lat, lng});
}


export async function checkPhone() {
  if (!get("phone")) {
    console.log("未授权手机号")
   // await goAuthorize()
    return false;
  }
  console.log("授权手机号")
  return true;
}
